package com.mdx.order.aop;

import com.mdx.order.controller.TestController;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @author : jiagang
 * @date : Created in 2025/1/9 09:41
 */
@Aspect
@Component
public class LogMethodAspect {
    private static final Logger LOG = LoggerFactory.getLogger(LogMethodAspect.class);

    // 定义切点，使用 @LogMethod 注解的方法
    @Pointcut("@annotation(com.mdx.order.annotation.LogMethod)")
    public void logMethodPointcut() {
    }

    // 在方法执行前进行日志记录
    @Before("logMethodPointcut()")
    public void logMethod(JoinPoint joinPoint) {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        LOG.info("开始执行方法 = {}", method.getName());
    }
}
